package net.lab1024.sa.admin.module.business.ball.bo;

import com.baomidou.mybatisplus.annotation.IdType;
import com.baomidou.mybatisplus.annotation.TableField;
import com.baomidou.mybatisplus.annotation.TableId;
import com.baomidou.mybatisplus.annotation.TableName;
import com.fasterxml.jackson.annotation.JsonInclude;
import lombok.Data;
import lombok.NoArgsConstructor;
import lombok.experimental.Accessors;
import lombok.extern.slf4j.Slf4j;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.List;

/**
 * 福彩3D开奖结果
 */
@Data
@Slf4j
@NoArgsConstructor
@TableName("tbl_lottery_3d")
@Accessors(chain = true)
@JsonInclude(JsonInclude.Include.NON_NULL)
public class Lottery3D {

    /**
     * 期号
     */
    @TableId
    private Integer phase;


    private Integer ball1;
    private Integer ball2;
    private Integer ball3;

    @TableField(exist = false)
    private Integer sum ;
    @TableField(exist = false)
    private Integer difference ;
    @TableField(exist = false)
    private String msg;

    public Integer getSum() {
        if (ball1 != null && ball2 != null && ball3 != null) {
            return (ball1 + ball2 + ball3) % 10;
        }
        return 0;
    }

    public void setSum(Integer sum) {
        this.sum = sum;
    }

    public Integer getDifference() {
        List<Integer> list = new ArrayList<>();
        if (ball1 != null) {
            list.add(ball1);
        }
        if (ball2 != null) {
            list.add(ball2);
        }
        if (ball3 != null) {
            list.add(ball3);
        }

        int max = Collections.max(list);
        int min = Collections.min(list);
        return max - min;
    }

    public void setDifference(Integer difference) {
        this.difference = difference;
    }

    public Lottery3D(String phase, String kaijiang) {
        this.phase =Integer.parseInt(phase);
        int[] digits = Arrays.stream(kaijiang.split("")).mapToInt(Integer::parseInt).toArray();
        ball1 = digits[0];
        ball2 = digits[1];
        ball3 = digits[2];
    }

}
